package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"house_srv/house"
	"house_srv/internal/svc"
	"house_srv/model/mysql"
)

type ListHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListHouseLogic {
	return &ListHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListHouseLogic) ListHouse(in *house.ListHouseRequest) (*house.ListHouseResponse, error) {
	// todo: add your logic here and delete this line
	var list []mysql.House
	mysql.DB.Find(&list)
	var Lists []*house.List
	for _, m := range list {
		h := house.List{
			HouseTitle:   m.HouseTitle,
			HouseAddress: m.HouseAddress,
			HouseIntro:   m.HouseIntro,
			HousePrice:   float32(m.HousePrice),
		}
		Lists = append(Lists, &h)

	}
	return &house.ListHouseResponse{List: Lists}, nil
}
